package com.itheima.dao;

import com.itheima.domain.Member;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;


/**
 * 会员数据的持久层
 */
public interface MemberDao {

    /**
     * 根据手机号查询会员数据
     *
     * @param telephone
     */
    @Select("select * from t_member where phoneNumber=#{telephone}")
    Member selectMemberByPhone(String telephone);


    /**
     * 添加会员
     *
     * @param member
     */
    void insertMember(Member member);


    /**
     * 根据日期查询当月注册会员数
     *
     * @param date
     * @return
     */
    @Select("select count(*) from t_member where regTime like concat(#{date},'%')")
    Integer selectMemberCountByMonth(String date);


    /**
     * 本日新增会员数
     *
     * @param date
     * @return
     */
    @Select("select count(id) from t_member where regTime =#{date}")
    Integer findMemberCountByDate(String date);

    /**
     * 查询本周或者本月新增会员数
     *
     * @param date
     * @return
     */
    @Select("select count(id) from t_member where regTime >=#{date}")
    Integer findMemberCountAfterDate(String date);

    /**
     * 查询总会员数
     *
     * @return
     */
    @Select("select count(id) from t_member")
    Integer findMemberTotalCount();

//    /**
//     * 查询本日，本周，本月和总共注册会员数
//     */
//    @Select("select count(id) from t_member where regTime =#{today}" +
//            "union all" +
//            "select count(id) from t_member where regTime =#{monday}" +
//            "union all" +
//            "select count(id) from t_member where regTime =#{month}" +
//            "union all" +
//            "select count(id) from t_member")
//    Map selectAllCount(@Param("today") String today,@Param("monday") String monday,@Param("month") String month);
}
